using UnityEngine;
using UnityEngine.UI;

namespace Gj
{
    public class RectHelper : CompareHelper
    {
        public Vector2 showRect;
        public Vector2 hideRect;
        public Vector4 showFullRect;
        public Vector4 hideFullRect;
        public bool isShow;
        public bool isHide;
        public bool full;
        public RectTransform rect;
        public GridLayoutGroup grid;

        public override void Show()
        {
            if (debug) LogTools.Log("{0} Show", gameObject.name);
            if (rect != null)
            {
                if (full)
                {
                    rect.offsetMin = new Vector2(showFullRect.x, showFullRect.w);
                    rect.offsetMax = new Vector2(showFullRect.z * -1, showFullRect.y * -1);
                }
                else
                {
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, showRect.x);
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, showRect.y);
                }
            }

            if (grid != null) grid.cellSize = showRect;
            isShow = true;
            isHide = false;
        }

        public override void Hide()
        {
            if (debug) LogTools.Log("{0} Hide", gameObject.name);
            if (rect != null)
            {
                if (full)
                {
                    rect.offsetMin = new Vector2(hideFullRect.x, hideFullRect.w);
                    rect.offsetMax = new Vector2(hideFullRect.z * -1, hideFullRect.y * -1);
                }
                else
                {
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, hideRect.x);
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, hideRect.y);
                }
            }

            if (grid != null) grid.cellSize = hideRect;
            isHide = true;
            isShow = false;
        }
    }
}